﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebService.BUS;

namespace WebService.Admin
{
    public partial class ItemsMultilang : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ListView1_Sorting(object sender, ListViewSortEventArgs e)
        {

        }

        protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "Insert")
            {
                DropDownList dllItem = (DropDownList)e.Item.FindControl("ddlUpItem");
                DropDownList dllLang = (DropDownList)e.Item.FindControl("ddlUpLanguage");
                TextBox txtDefault = (TextBox)e.Item.FindControl("txtIsDefault");
                TextBox txtName = (TextBox)e.Item.FindControl("txtName");
                TextBox txtAdd = (TextBox)e.Item.FindControl("txtAdd");
                TextBox txtNote = (TextBox)e.Item.FindControl("txtNotee");
                string insertCommand = "Insert into [tbl_ItemsTranslation] Values('" + dllItem.SelectedValue + "','"
                    + dllLang.SelectedValue + "','"
                    + txtDefault.Text + "','"
                    + txtName.Text + "','"
                    + txtAdd.Text + "','"
                    + txtNote.Text + "');";
                SqlDataSource1.InsertCommand = insertCommand;
            }
            else if (e.CommandName == "Update")
            {
                TextBox txtId = (TextBox)e.Item.FindControl("txtUpId");
                TextBox txtDefault = (TextBox)e.Item.FindControl("txtUpIsDefault");
                TextBox txtName = (TextBox)e.Item.FindControl("txtUpName");
                TextBox txtAdd = (TextBox)e.Item.FindControl("txtUpAdd");
                TextBox txtNote = (TextBox)e.Item.FindControl("txtUpNotee");
                string updateCommand = "Update [tbl_ItemsTranslation] set [ItemName]=N'" + txtName.Text + "',[Note]=N'" + txtNote.Text + "', [Address]=N'" + txtAdd.Text + "',[IsDefault]='" + txtDefault.Text +
                    "' where Id=" + txtId.Text + ";";
                SqlDataSource1.UpdateCommand = updateCommand;
            }
            else if (e.CommandName == "Delete")
            {
                TextBox txtId = (TextBox)e.Item.FindControl("txtUpId");
                string deleteCommand = "delete from [tbl_ItemsTranslation] where Id=" + txtId.Text;
                SqlDataSource1.DeleteCommand = deleteCommand;
            }
        }

        protected void ddlUpItem_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList dllItem = (DropDownList)sender;
            ItemBUS itemBUS = new ItemBUS();
            TextBox txtAddress = (TextBox)FindControl("txtAddress");
            //txtAddress.Text = itemBUS.getItems(dllItem.SelectedValue, "vi").Address.ToString();
        }
    }
}